<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class MY_Controller extends CI_Controller {

     public function __construct() {
        parent::__construct();

        /** 加载后台控制器公共库 */
        $this->load->library('session');
        /** 检查登陆 */
        if(empty($_SESSION['user'])){
            $this->session->set_flashdata('err', '您还没有登陆，或者登陆过期');
            redirect(site_url('home/index'));
        }

    }

    /**
     * 视图加载
     */
    protected function _view($str,$data=array()){
        $data['sess_user'] = $this->session->user;

        //判断是否为手机登陆
        $this->load->library('mobile_lib');
        $data['mobile'] = $this->mobile_lib->is_mobile_request();

        //导入菜单
        $data['menu'] = $this->load->view('layout/menu','',TRUE);

        $c = $this->uri->segment(1, 0);

        //获取公告标题
        if(!isset($this->comment_mdl)){
            $this->load->model('comment_mdl');
        }
        $data['comment'] = $this->comment_mdl->get_comm_one();

        $this->load->view('layout/head',$data);
        $this->load->view("$c/".$str);
        $this->load->view('layout/bottom');



    }

    /** 邮件通知（通知管理员） */
    /**
     * 邮件通知
     * @param  $to      收信人邮箱
     * @param  $title   邮件标题
     * @param  $content 邮件内容
     */
    protected function send_admin($to,$title,$content){

        $this->load->library('email');

        //设置发信人email地址和名称
        $this->email->from('zbzmall@yeah.net', $this->session->config->title, $this->session->config->email);
        //设置邮件回复地址
        $this->email->reply_to($this->session->config->email, $this->session->config->title);
        //设置发送地址
        $this->email->to($to);

        $this->email->subject($title);//主题
        $this->email->message($content); //内容

        return $this->email->send();
    }

    function send_post($url,$post_data) {

        $postdata = http_build_query($post_data);
        $options = array(
            'http' => array(
            'method' => 'POST',
            'header' => 'Content-type:application/x-www-form-urlencoded',
            'content' => $postdata,
            'timeout' => 15 * 60 // 超时时间（单位:s）
        )
        );
        $context = stream_context_create($options);
        $result = file_get_contents($url, false, $context);

        return $result;
    }

}

/* End of file MY_Controller.php */
/* Location: ./application/core/MY_Controller.php */